<?php
declare (strict_types=1);

namespace app\common\middleware;

use think\facade\Request;

class Auth
{
    /**
     * 处理请求
     * @param \think\Request $request
     * @param \Closure $next
     * @return Response
     */
    public function handle($request, \Closure $next)
    {
        //获取请求的时候头部携带着这个token
        $token = GetToken("id");
        if (empty($token)) {
            if (Request::isAjax() || Request::isPost()) {
                return BackCode(null, 201, '请先登陆！');
            } else {
                return redirect((string)url('/admin/index/login'));
            }
        }
        return $next($request);
    }
}